/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.service.impl;

import com.legendshop.dao.support.PageSupport;
import com.legendshop.oa.dao.WeekLogDao;
import com.legendshop.oa.dto.WeekLogReport;
import com.legendshop.oa.model.WeekLog;
import com.legendshop.oa.service.WeekLogService;
import com.legendshop.util.AppUtils;

import java.util.Date;
import java.util.List;

/**
 * The Class WeekLogServiceImpl. 周报服务实现类
 */
public class WeekLogServiceImpl implements WeekLogService {

	/**
	 *
	 * 引用的周报Dao接口
	 */
	private WeekLogDao weekLogDao;

	public void setWeekLogDao(WeekLogDao weekLogDao) {
		this.weekLogDao = weekLogDao;
	}

	/**
	 * 根据商城获取周报列表
	 */
	public List<WeekLog> getWeekLog(String userName) {
		return weekLogDao.getWeekLog(userName);
	}

	/**
	 * 根据Id获取周报
	 */
	public WeekLog getWeekLog(Long id) {
		return weekLogDao.getWeekLog(id);
	}

	/**
	 * 删除周报
	 */
	public int deleteWeekLog(WeekLog weekLog) {
		return weekLogDao.deleteWeekLog(weekLog);
	}

	/**
	 * 保存周报
	 */
	public Long saveWeekLog(WeekLog weekLog) {
		if (!AppUtils.isBlank(weekLog.getId())) {
			updateWeekLog(weekLog);
			return weekLog.getId();
		}
		return weekLogDao.saveWeekLog(weekLog);
	}

	/**
	 * 更新周报
	 */
	public void updateWeekLog(WeekLog weekLog) {
		weekLogDao.updateWeekLog(weekLog);
	}

	@Override
	public PageSupport<WeekLog> getWeekLogByLeaderUserNameDate(String leaderName, String curPageNO, String name, String realName, Date startDate, Date endDate) {
		return weekLogDao.getWeekLogByLeaderUserNameDate(leaderName, curPageNO,name, realName,startDate, endDate );
	}

	@Override
	public WeekLog getWeekLog(String userName, Integer year, Integer weekNo) {
		return weekLogDao.getWeekLog(userName,year, weekNo);
	}

	/**
	 * 获取用户的周报,查询下属的周报
	 * @param curPageNO 页码
	 * @param userName 用户名
	 * @param year 年
	 * @param weekNo 第几周
	 * @return
	 */
	@Override
	public PageSupport<WeekLog> getUserWeekLogList(boolean isAdmin, String leaderName, String curPageNO, String userName, Integer year, Integer weekNo) {
		if(AppUtils.isBlank(userName)) {
			return weekLogDao.getWeekLogByLeaderYearWeek(isAdmin,leaderName, curPageNO,year, weekNo );
		}else {
			return weekLogDao.getWeekLogByUserYearWeek(isAdmin, leaderName, curPageNO,userName,year, weekNo );
		}
	}

	@Override
	public boolean isMycolleague(String leaderName, String userName) {
		return weekLogDao.isMycolleague(leaderName, userName);
	}

	@Override
	public List<WeekLogReport> getUserWeekLogList(WeekLog weekLog) {
		return weekLogDao.getWeekLogReport(weekLog);
	}


}
